package com.example.gzq.mymusictest;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Toast;

/**
 * Created by gzq on 17-7-14.
 */

public class BaseStyle extends AppCompatActivity {
    protected static String mNub;
    protected LocalBroadcastManager localBroadcastManager;
    private  LocalReceiver localReceiver;
    private static final String TAG = "BaseStyle";
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActionBar actionBar=getSupportActionBar();
        mNub="";
        localBroadcastManager=LocalBroadcastManager.getInstance(this);
        if(actionBar!=null){
            actionBar.hide();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        IntentFilter intentFilter=new IntentFilter();
        intentFilter.addAction("com.example.gzq.mymusictest.Registered");
        localReceiver=new LocalReceiver();
        localBroadcastManager.registerReceiver(localReceiver,intentFilter);
    }

    @Override
    protected void onPause() {
        super.onPause();
        localBroadcastManager.unregisterReceiver(localReceiver);
    }
    class LocalReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            Toast.makeText(context,"注册成功！",Toast.LENGTH_SHORT).show();
            mNub=intent.getStringExtra("mNub");
            Log.d(TAG, "onReceive: mNub="+mNub);
        }
    }
}
